package com.yuanqi.Controller;

import com.yuanqi.Mapper.ImageMapper;
import com.yuanqi.Common.Pojo.Dto.PostDto;
import com.yuanqi.Common.Pojo.Vo.PostDetail;
import com.yuanqi.Common.Pojo.Vo.PostVo;
import com.yuanqi.Common.Pojo.entity.PostClass;
import com.yuanqi.Return.Result;
import com.yuanqi.Service.PostService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/v1/post")
public class PostController {

    @Resource
    private PostService postService;
    @Resource
    private ImageMapper imageMapper;

    /**
     * 获取分类
     * @return
     */
    @GetMapping("/getList")
    public Result getList()
    {
      List<PostClass> list = postService.getList();
      return Result.success(list);
    }

    /**
     * 删除图片
     * @param id
     * @return
     */
    @DeleteMapping("/delImg")
    public Result delImg(@RequestBody List<Long> id)
    {
        imageMapper.deleteBatchIds(id);
        return Result.success();
    }

    /**
     * 发布文章
     * @param postdto
     * @return
     */
    @PostMapping("/publish")
    public Result publish(@RequestBody PostDto postdto)
    {
        postService.publish(postdto);
        return Result.success();
    }

    /**
     * 获取详情页
     * 用户头像名称
     * 分享文章
     * 图片
     * 文章
     * @param id
     * @return
     */
    @GetMapping("/getDetail")
    public Result getDetail(Long id)
    {
        PostDetail postDetail = postService.getDetail(id);
        return Result.success(postDetail);
    }

    @GetMapping("/getPostByClassId")
    public Result getPostByClassId(Long id,Integer current,Long UserId)
    {
        List<PostVo> list = postService.getPostByClassId(id,current,UserId);
        return Result.success(list);
    }

    /**
     * 获取指定用户下的公开文章
     * @param Userid
     * @param current
     * @return
     */

    @GetMapping("/getPostByUserId")
    public Result getPostByUserId(Long Userid,Integer current,Long loginUserId)
    {
        List<PostVo> list = postService.getPostByUserId(Userid,current,loginUserId);
        return Result.success(list);
    }
    @GetMapping("/getPostByLoginUser")
    public Result getPostByLoginUser()
    {
        List<PostVo> list = postService.getPostByLoginUser();
        return Result.success(list);
    }

    @PostMapping("/SearchPost")
    public Result SearchPost(@RequestBody PostDto postDto)
    {
        List<PostVo> list = postService.SearchPost(postDto);
        return Result.success(list);
    }

    @GetMapping("/getConcernPost")
    public Result getConcernPost( Integer current)
    {
        List<PostVo> list = postService.getconcernpost(current);
        return Result.success(list);
    }
}
